package com.lcxw.hxzbapi.dao.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.lcxw.hxzbapi.entity.pojo.AddCoin;

@Mapper
public interface AddCoinMapper {

    @Delete({
        "delete from ywpd_addcoin",
        "where `id` = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into ywpd_addcoin (`userId`, `addCoin`, ",
        "`addTime`, `adminName`, ",
        "`ip`)",
        "values (#{userId}, #{addCoin}, ",
        "#{addTime}, #{adminName}, ",
        "#{ip})"
    })
    int insert(AddCoin record) throws Exception;

    @Select({
        "select",
        "*",
        "from ywpd_addcoin",
        "where `id` = #{id,jdbcType=INTEGER}"
    })
    AddCoin selectByPrimaryKey(Integer id);

    @Select({
        "select",
        "*",
        "from ywpd_addcoin",
        "where `id` = #{id,jdbcType=INTEGER}"
    })
    List<AddCoin> selectAll();

    @Update({
        "update ywpd_addcoin",
        "set `userId` = #{userId},",
        "`addCoin` = #{addCoin},",
        "`addTime` = #{addTime},",
        "`adminName` = #{adminName},",
        "`ip` = #{ip}",
        "where `id` = #{id}"
    })
    int updateByPrimaryKey(AddCoin record);

    @Select("<script>" + "SELECT COUNT(*) FROM ywpd_addcoin WHERE "
        + "<if test='userId!=null'>"
        + "userId = #{userId} and "
        + "</if>"
        + "<if test='startTime!=null'>"
        + "addTime &gt;= #{startTime} and "
        + "</if>"
        + "<if test='endTime!=null'>"
        + "addTime &lt;= #{endTime} and "
        + "</if>"
        + "<if test='adminName!=null'>"
        + "adminName=#{adminName} and "
        + "</if>"
        + "1=1"
        + "</script>")
    int selectSumAddCoinDync(@Param("userId") Long userId,
        @Param("startTime") String startTime,
        @Param("endTime") String endTime, @Param("adminName") String adminName);


    @Select("<script>" + "SELECT * FROM ywpd_addcoin WHERE "
        + "<if test='userId!=null'>"
        + "userId = #{userId} and "
        + "</if>"
        + "<if test='startTime!=null'>"
        + "addTime &gt;= #{startTime} and "
        + "</if>"
        + "<if test='endTime!=null'>"
        + "addTime &lt;= #{endTime} and "
        + "</if>"
        + "<if test='adminName!=null'>"
        + "adminName=#{adminName} and "
        + "</if>"
        + "1=1"
        + " LIMIT #{pageIndex},#{pageSize} "
        + "</script>")
    List<AddCoin> selectAddCoinDync(@Param("userId") Long userId,
        @Param("startTime") String startTime,
        @Param("endTime") String endTime, @Param("adminName") String adminName,
        @Param("pageIndex") int pageIndex, @Param("pageSize") int pageSize);


}
